package com.uxwine.alarm.mon;

import java.util.Calendar;

import com.uxwine.util.ClassReflect;

import android.app.Service;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.format.DateFormat;

public class AlarmContext
{

	public final static String DM12 = "E h:mm aa";
	public final static String DM24 = "E k:mm";
	
	public final static String YMDHM12 = "yyyy/MM/dd h:mm aa";
	public final static String YMDHM24 = "yyyy/MM/dd kk:mm";

	public final static String YMDE = "yyyy/MM/dd EEEE";
	public final static String YMD = "yyyy/MM/dd";
	public final static String MD = "MM/dd";
	

	public final static String MDHM12 = "MM/dd h:mm aa";
	public final static String MDHM24 = "MM/dd kk:mm";
	

	public final static String DHM12 = "dd h:mm aa";
	public final static String DHM24 = "dd k:mm";

    public final static String M12 = "h:mm aa";
    public final static String M24 = "kk:mm";
    
	private static AlarmContext mInstance;
	private Context mCtx;
	private String mPakgeName;
	
	private AlarmContext(Context ctx)
	{
		mCtx = ctx;
		mPakgeName = ctx.getPackageName();
	}
	
	public static synchronized AlarmContext getInstance(Context ctx)
	{
		if(null == mInstance)
		{
			mInstance = new AlarmContext(ctx);
		}
		return mInstance;
	}
	
	public Class<?> getAlertActivity(boolean bFullscreen)
	{
		String className = bFullscreen ? 
				"com.nny.alarm.alert.AlertActivity" :
					"com.nny.alarm.alert.AlertActivity";
		return ClassReflect.classForName(className);
	}
	
	public Class<?> getMainActivity()
	{
		return ClassReflect.classForName("com.nny.alarm.MainActivity");
	}
	
	public int getRingTimeOut()
	{
		return 10 * 60;
	}
	
	public int getAlartIcon()
	{
		return getDrawableId("ic_launcher");
	}
	
	public int getDrawableId(String id)
	{
		final Resources res = mCtx.getResources();
		return res.getIdentifier(id, "drawable", mPakgeName);
	}
	
	/* used by AlarmAlert */
	public static String formatTime(final Context context, Calendar c) 
	{
		String format = get24HourMode(context) ? M24 : M12;
		return (c == null) ? "" : (String)DateFormat.format(format, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatWeekDayAndTime(final Context context, Calendar c) 
	{
		String format = get24HourMode(context) ? DM24 : DM12;
		return (c == null) ? "" : (String)DateFormat.format(format, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatYMDHM(final Context context, Calendar c) 
	{
		String format = get24HourMode(context) ? YMDHM24 : YMDHM12;
		return (c == null) ? "" : (String)DateFormat.format(format, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatMDHM(final Context context, Calendar c) 
	{
		String format = get24HourMode(context) ? MDHM24 : MDHM12;
		return (c == null) ? "" : (String)DateFormat.format(format, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatDHM(final Context context, Calendar c) 
	{
		String format = get24HourMode(context) ? DHM24 : DHM12;
		return (c == null) ? "" : (String)DateFormat.format(format, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatMD(final Context context, Calendar c) 
	{
		return (c == null) ? "" : (String)DateFormat.format(MD, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatD(final Context context, Calendar c) 
	{
		return (c == null) ? "" : (String)DateFormat.format("dd", c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatYMD(final Context context, Calendar c) 
	{
		return (c == null) ? "" : (String)DateFormat.format(YMD, c);
	}
	
	/**
	* Shows day and time -- used for lock screen
	*/
	public static String formatYMDE(final Context context, Calendar c) 
	{
		return (c == null) ? "" : (String)DateFormat.format(YMDE, c);
	}
	
	/**
	* @return true if clock is set to 24-hour mode
	*/
	public static boolean get24HourMode(final Context context) 
	{
		return android.text.format.DateFormat.is24HourFormat(context);
	}
}
